import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'
import '@/icons' // icon
import '@/permission' // permission control
import '@/styles/common.scss'
// set ElementUI lang to EN
Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)

import PageTools from '@/components/index.js'
Vue.use(PageTools)

import mixin from './mixin'
Vue.mixin(mixin)

// 自定义指令
Vue.directive('fixImg', {
  inserted(el) {
    el.src = el.src || require('@/assets/common/logo-64.png')
    // 图片的报错处理
    el.addEventListener('error', () => {
      el.src = require('@/assets/common/head.jpg')
    })
  }
})

// Vue.filter('formatData', (oldval) => {
//   const date = new Date(oldval)
//   return date.toLocaleDateString()
// })

import * as myFilter from '@/filters'
for (const key in myFilter) {
  Vue.filter(key, myFilter[key])
}

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
